//
//  FriendListContext.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/4/22.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "FriendListContext.h"
#import "PlistManager.h"
//#import "FriendListViewModel.h"
//#import "ApplyFriendListViewModel.h"

@interface FriendListContext ()

//@property (nonatomic, strong) FriendListViewModel *friendListViewModel;
//
//@property (nonatomic, strong) ApplyFriendListViewModel *applyFriendListViewModel;

@end

@implementation FriendListContext

static FriendListContext *_friendListContext = nil;

#pragma mark - Initialize
+ (instancetype)sharedInstance{
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        _friendListContext = [[self alloc] init];
    });
    
    return _friendListContext;
}

#pragma mark - Public
- (void)loadFriendListFromServer{
    NSUInteger userId = [AppContext sharedInstance].userId;
    
    if (userId > 0) {
//        NSArray *viewsArray = [NSArray arrayWithObjects:_conversationListController,_chatViewController, nil];
//        self.friendListViewModel.viewObject = viewsArray;
//        [self.friendListViewModel loadRequest];
    }
}

- (void)loadApplyFriendListFromServerWithHXAccountArray:(NSArray *)hxAccountArray{
    NSUInteger userId = [AppContext sharedInstance].userId;
    
    if (userId > 0) {
//        NSDictionary *postDic = @{@"hxAccounts":hxAccountArray};
//        self.applyFriendListViewModel.postObject = postDic;
//        [self.applyFriendListViewModel loadRequest];
    }
}

//- (AddFriendModel *)getUserApplyFriendModelByHXAccount:(NSString *)hxAccount{
//    if (_friendList != nil) {
//        
//        for (AddFriendModel *addFriendModel in _applyFriendList) {
//            if ([addFriendModel.hxAccount isEqualToString:hxAccount]) {
//                return addFriendModel;
//            }
//        }
//    }
//    
//    return nil;
//}

- (UserFriendModel *)getUserFriendModelByFriendId:(NSInteger)friendId{
    if (friendId != 0) {
        
        for (UserFriendModel *userFriendModel in _friendList) {
            
            if (userFriendModel.friendId == friendId) {
                
                return userFriendModel;
            }
        }
        
    }
    return nil;
}

- (UserFriendModel *)getUserFriendModelByHXAccount:(NSString *)hxAccount{
    if (_friendList != nil) {
        
        for (UserFriendModel *userFriendModel in _friendList) {
            if ([userFriendModel.hxAccount isEqualToString:hxAccount]) {
                return userFriendModel;
            }
        }
    }
    
    return nil;
}

- (UserFriendModel *)getUserFriendModelByFriendName:(NSString *)friendName{
    if (_friendList != nil) {
        
        for (UserFriendModel *userFriendModel in _friendList) {
            if ([userFriendModel.friendName isEqualToString:friendName]) {
                return userFriendModel;
            }
        }
    }
    
    return nil;
}

//#pragma mark - Getter
//- (FriendListViewModel *)friendListViewModel{
//    
//    if (_friendListViewModel == nil) {
//        _friendListViewModel = [FriendListViewModel new];
//    }
//    
//    return _friendListViewModel;
//}
//
//- (ApplyFriendListViewModel *)applyFriendListViewModel{
//
//    if (_applyFriendListViewModel == nil) {
//        _applyFriendListViewModel = [ApplyFriendListViewModel new];
//    }
//    return _applyFriendListViewModel;
//}

#pragma mark - Setter
- (void)setFriendList:(NSArray *)friendList{
    _friendList = friendList;
}

- (void)setApplyFriendList:(NSArray *)applyFriendList{
    _applyFriendList = applyFriendList;
    if (_applyFriendSuccessBlock != nil) {
        _applyFriendSuccessBlock();
    }
}

@end
